package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-09-30
 * Time:11:37
 */
public class BorrowOperation implements IOperation{
    @Override
    public void ioperation(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入要借阅图书的名字：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        //匹配图书
        for (int i = 0; i < bookList.getUseSize(); i++) {
            Book book=bookList.getPos(i);
            if(name.equals(book.getName())){
                if(book.getBorrow()==false){
                    book.setBorrow(true);
                    System.out.println(name+"借阅成功");
                }else{
                    System.out.println("此书已被借阅，不可再次借阅");
                }
            }
            if(i== bookList.getUseSize()){
                System.out.println("没有这本书");
            }
        }

    }
}
